<!--#
layout("/layouts/store.html"){
#-->
<link rel="stylesheet" href="${base!}/assets/platform/vendor/layui/css/layui.css">
<section class="content-wrap bg-white">
    <header class="header bg-white navbar shadow">
        <header class="header navbar bg-white shadow">
            <div class="btn-group tool-button" style="padding-top: 8px;">
                <form class="form-inline js-search-form" >
                    <div class="form-group">
                        <label class="control-label"></label>
                        <input type="text" class="form-control" name="mobile" placeholder="手机号" />
                    </div>
                    <div class="form-group">
                        <label class="control-label"></label>
                        <input type="text" class="form-control" name="nickName" placeholder="微信昵称" />
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary js-search-ok" >${msg['globals.button.search']}</button>
                        <button type="button" class="btn btn-default js-search-reset" >${msg['globals.button.reset']}</button>
                    </div>
                </form>
            </div>
            <div class="btn-group tool-button pull-right">
                <!--            <a id="add" class="btn btn-primary navbar-btn" onclick="hexiao()" href="javascript:void(0)" data-pjax><i class="ti-plus"></i> 核销</a>-->
                <!--            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> ${msg['globals.button.delete.more']}</button>-->
            </div>
        </header>
    </header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border" style="min-height: 800px;">
            <table class="table table-bordered table-striped mg-t datatable">
                <thead>
                <tr>
                    <th>${msg['account.info.column.nickname']}</th><!--用户名-->
                    <th>${msg['account.user.column.mobile']}</th><!--昵称-->
                    <th>可用积分</th><!--类型-->
                    <!--<th>${msg['member.level.memberLevel']}</th>&lt;!&ndash;等级&ndash;&gt;-->
                    <!--<th>${msg['account.user.column.mobile']}</th>&lt;!&ndash;手机号&ndash;&gt;-->
                    <th>${msg['globals.table.column.operation']}</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</section>

<div id="dialogDetail" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<div id="dialogPaasword" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">重置密码</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn-block" data-dismiss="modal">知道了</button>
            </div>
        </div>
    </div>
</div>
<div id="dialogCoupon" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<style>
   /* .dropdown-menu{
        width: 100px !important;
    }
    .dropdown-menu li{
        width: 100px !important;
    }*/
</style>
<script src="${base!}/assets/platform/vendor/layui/layui.all.js"></script>
<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/platform/vendor/datatables/locale/${lang}.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/store/member/user/datax",
                "type": "post",
                "data": function (d) {
                    var $searchForm = $(".js-search-form");
                    d.mobile = $("[name='mobile']", $searchForm).val()||"";
                    d.nickName = $("[name='nickName']", $searchForm).val()||"";
                }
            },
            // "order": [[0, "asc"]],
            "columns": [
                {"data": "nickname", "sortable": true},
                {"data": "name", "bSortable": true, "render":
                        function (data, type, row) {
                            if(row.name == null|| row.name == ''){
                                return '未绑定';
                            }else {
                                return row.name;
                            }
                        }
                },
                {"data": "useAbleIntegral", "bSortable": true},
                // {"data": "money", "bSortable": true},
                // {"data": "mobile", "bSortable": true},
                // {"data": "state", "bSortable": true}
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        var returnHtml = '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                            ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">'
                        returnHtml +=  '<li><a href="javascript:void(0)" onclick="alertLayer(\'' + row.id + '\')" data-pjax>抵扣积分</a></li>' +
                            '<li class="divider"></li>'
                        returnHtml += '</ul></div>';
                        return returnHtml;
                    },
                    "targets": 3
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            $("#emptyBtn").show();
            datatable.ajax.reload();
        });
        $("#emptyBtn").on('click', function () {
            $("#type").val("");
            $("#level").val("");
            $("#query").val("");
            datatable.ajax.reload();
        });

        $(".js-search-ok").click(function () {
            datatable.ajax.reload();
        });

        $(".js-search-reset").click(function () {
            $(".js-search-form").resetForm();
            // $('.datatable').DataTable().ajax.reload();
        });
    }

    $(function () {
        initDatatable();
        $("#dialogDetail").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    });

    function resetPwd(id) {
        $.post("${base}/store/member/user/resetPwd/" + id, {}, function (data) {
            var dialog = $("#dialogPaasword");
            if (data.code == 0) {
                dialog.find(".col-xs-12").html("密码重置成功，请复制新密码：" + data.data);
                dialog.modal("show");
            } else {
                dialog.find(".col-xs-12").html(data.msg);
                dialog.modal("show");
            }
        }, "json");
    }

    /**
     * 当会员类型改变时，查找该类型对应的等级列表并填充到等级选择框中,同时刷新列表
     * @param elem 当前元素
     */
    function reloadLevelSelect(elem) {
        var typeId = $(elem).val();
        if (!typeId){
            return;
        }

        $.post("${base}/store/member/level/getLevelListByTypeId", {typeId: typeId}, function (result) {
            //重新初始化
            $("#level").html("").append('<option value="">请选择会员等级</option>');

            if (result.code == 0) {
                var levelList = result.data;
                if (!levelList || levelList.length < 1) {
                    var options = elem.options;
                    var index = elem.selectedIndex;
                    var val = options[index].text;
                    Toast.info("暂无" + val + "的等级信息");
                    return;
                }

                for (var i = 0; i < levelList.length; i++) {
                    var levelObj = levelList[i];
                    $("#level").append('<option value="' + levelObj.id + '">' + levelObj.name + '</option>');
                }
            } else {
                Toast.error(result.msg);
            }
        }, "json");
        $("#level").show();
        $("#emptyBtn").show();
        datatable.ajax.reload();
    }

    var htmlIndex = "";
    function alertLayer(accountId) {
        //页面层
        htmlIndex= layer.open({
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['720px', '340px'], //宽高
            content: '<section class="panel panel-form" id="kouJIfenHtml">\n' +
                '    <div id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate>\n' +
                '        <div class="row mb10 mt10">\n' +
                '            <div class="col-lg-10">\n' +
                '                <div class="form-group">\n' +
                '                    <label for="jfNum" class="col-sm-2 control-label">抵扣积分数</label>\n' +
                '                    <div class="col-sm-8">\n' +
                '                        <input type="number" id="jfNum" class="form-control" name="jfNum" data-parsley-required="true" placeholder="0">\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '                <div class="form-group">\n' +
                '                    <label for="jfDesc" class="col-sm-2 control-label">备注说明</label>\n' +
                '                    <div class="col-sm-8">\n' +
                '                        <input type="text" id="jfDesc" class="form-control" name="jfDesc" data-parsley-required="true" placeholder="兑换1000元代金券或兑换抱枕">\n' +
                '                    </div>\n' +
                '                </div>\n' +
                '                <input type="hidden" id="accountId" class="form-control" value="" name="accountId">\n' +
                '            </div>\n' +
                '        </div>\n' +
                '        <div class="col-lg-3"></div>\n' +
                '        <div class="col-lg-6">\n' +
                '            <div class="form-group text-center">\n' +
                '                <div>\n' +
                '                    <button type="button" class="btn btn-primary btn-block" onclick="minusPoints()" id="jfBoot" data-dismiss="modal">提交</button>\n' +
                '                </div>\n' +
                '            </div>\n' +
                '        </div>\n' +
                '    </div>\n' +
                '</section>'
        });
        $("#accountId").val(accountId);
    }

    //抵扣积分
    function minusPoints() {
        if($("#jfNum").val() == ''){
            layer.msg("积分数不能为空", {icon: 2});
            return;
        }
        if($("#jfNum").val() < 0){
            layer.msg("积分数不能为负数", {icon: 2});
            return;
        }
        if($("#jfDesc").val() == ''){
            layer.msg("备注不能为空", {icon: 2});
            return;
        }
        //询问框
        layer.confirm('确认扣减积分', {
            btn: ['是','否'] //按钮
        }, function(){
        //询问框
            $.ajax({
                type: "post",
                url: "${base}/store/integral/Integral/minusPoints",
                data: {
                    im : $("#jfNum").val(),
                    accountId: $("#accountId").val(),
                    desc:$("#jfDesc").val()
                },
                dataType: "json",
                async: false,
                success: function(data){
                    if (data.code == 0) {
                        layer.msg('扣减成功', {icon: 1});
                        datatable.ajax.reload(null,false);
                        layer.close(htmlIndex)
                    }else{
                        layer.msg(data.msg, {icon: 2});
                    }
                }
            });
        }, function(){

        });
    }
</script>
<!--#}#-->